package com.yida.system.config;

import cn.hutool.core.util.ObjectUtil;
import com.yida.common.core.constant.CacheConstants;
import com.yida.common.redis.service.RedisService;
import com.yida.system.api.vo.SysDataPutInInterfaceVO;
import com.yida.system.mapper.SysDataPutInInterfaceConfigMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @Description 系统数据对接接口配置参数
 * @Author wws
 * @Date 2023-04-04
 */
@Configuration
public class DataPutInInterfaceConfig {

    @Autowired
    private SysDataPutInInterfaceConfigMapper sysDataPutInInterfaceConfigMapper;

    @Autowired
    private RedisService redisService;

    @Bean
    public void initDataPutInConfig(){
        List<SysDataPutInInterfaceVO> sysDataPutInInterfaceVOList = sysDataPutInInterfaceConfigMapper.selectDataPutInterfaceVO();
        if(ObjectUtil.isEmpty(sysDataPutInInterfaceVOList)){
            return;
        }
        sysDataPutInInterfaceVOList.forEach(item -> {
            String key = CacheConstants.SYS_DATA_PUT_IN
                    + CacheConstants.REDIS_SUFFIX
                    + item.getConfigKey()
                    + CacheConstants.REDIS_SUFFIX
                    + item.getInterfaceCode();
            if(!redisService.hasKey(key)){
                redisService.setCacheObject(key,item);
            }
        });
    }

}
